
local MainScene = class("MainScene", cc.load("mvc").ViewBase)

local function TestSceneScheduler(self)
    local scheduler = self:getScheduler()
    scheduler:scheduleScriptFunc(function()
        release_print("test scene scheduler")
    end, 1, false)
end

function MainScene:onCreate()
    local scheduler = cc.Director:getInstance():getScheduler()
    local id1 = scheduler:scheduleScriptFunc(function()
        release_print("called every frame") -- 每一帧都被调用
    end, 0, false)

    local interval = 1
    local sec = 0
    local id2
    id2 = scheduler:scheduleScriptFunc(function()
        release_print("called every interval")

        sec = sec + interval
        if id1 and sec >= 3 then
            scheduler:unscheduleScriptEntry(id1)
            id1 = nil
            release_print("**stop** called every frame")
        end

        if id2 and sec >= 6 then
            scheduler:unscheduleScriptEntry(id2)
            id2 = nil
            release_print("**stop** called every interval")

            TestSceneScheduler(self)
        end
    end, interval, false)
end

return MainScene
